--boss令

--#include "data\config\item\BossToken.lua" once


function UseBossToken(sysarg, itemidx, itemPtr,ItemTable, delType)
	local curSceneId = Actor.getSceneId(sysarg)
	local state = false
	if type(bossTokenConfig.senceId) == 'table' then
		for idx = 1, #bossTokenConfig.senceId do
			if curSceneId == bossTokenConfig.senceId[idx] then
				state = true
				break
			end
		end
	elseif type(bossTokenConfig.senceId) == 'number'  then
		if curSceneId == bossTokenConfig.senceId then
			state = true
		end
	else
		return
	end
	
	if not state then
		Actor.sendTipmsg( sysarg, Lang.ScriptTips.UseBossToken001, ttFlyTip )
		return
	end
	if Actor.hasMapAreaAttri(sysarg, aaCanNotCallMonster) then
		Actor.sendTipmsg( sysarg, Lang.ScriptTips.UseBossToken004, ttFlyTip )
		return
	end
	local SenceName,x,y = Actor.getSceneName(sysarg,0,0)
	local logId, logStr = LogIds.UseBossTokenLogId, Lang.LogTips.UseBossToken
	if Actor.removeItemByPtr(sysarg, itemPtr, 1, true, logStr, logId) > 0 then
		--if AddDailyItemUseCount(sysarg, itemidx, 1)	then		--次数增加，并发送客户端
		local bossId,tipType
		if type(ItemTable.bossId) == "number" then
			bossId = ItemTable.bossId
			tipType = 1
		else
			local idx,ItemTableInfo = GetItemIdxRand(ItemTable.bossId)
			bossId = ItemTableInfo.newBossId
			tipType = 2
		end
		BossTokenMonsterCreate(sysarg, bossId, x, y, tipType, SenceName)
		return true
	end

end

function BossTokenMonsterCreate(sysarg, bossId, x, y, tipType, SenceName)			--boss创建
	local hScene = Actor.getSceneHandle(sysarg)
	bossarg = Fuben.createMonster(hScene, bossId, x, y, bossTokenConfig.lastTime)
	bossName = System.getMonsterNameById(bossId)
	local tip
	if tipType == 1 then
		tip = string.format(Lang.ScriptTips.UseBossToken002, Actor.getName(sysarg), SenceName, bossName, x, y, Actor.getSceneId(sysarg))
	else
		tip = Lang.ScriptTips.UseBossToken005
	end
	System.broadcastTipmsgLimitLev(tip , ttChatWindow, bossTokenConfig.BroadCastLevel )

	local actorId = Actor.getActorId(sysarg)
	Actor.regScriptTimer(bossarg, 0, bossTokenConfig.lastTime * 1000, 0, 1, "OnUseTokenBossEnd", actorId)
end

function UseBossTokenInit(sysarg)
    for i = 1,table.getn(bossTokenConfig.bossTokenList) do
	    local x = bossTokenConfig.bossTokenList[i]
	    GlobalItemFn[x.itemId] = { func = UseBossToken, params = x }
    end
end

table.insert(InitFnTable, UseBossTokenInit)

